<?php

class Admin_testimonials_model extends CI_Model{

	//retrieve all data
	function listTestimonials(){
		return $this->db->get('mlme_testimonials');
	}

	//to be used in pagination
	function listTestimonials_limited( $start_row=0, $limit=100 ){
		$qry = "SELECT a.*,b.firstname as userfname,b.lastname as userlname FROM mlme_testimonials a LEFT JOIN mlme_users b ON a.userid = b.userid ORDER BY a.date_added DESC limit $start_row, $limit";
		return $this->db->query($qry);
	}

	//get the data
	//@param id: testiid
	function getTestimonial( $id=null ){
		return $this->db->get_where('mlme_testimonials', array('testimonialid' => $id ));
	}

	//delete data
	function deleteTestimonial( $id=array() ){
		if( empty($id) ) return false;
		$this->db->where_in( 'testimonialid', $id );
		return $this->db->delete('mlme_testimonials');
	}
	
	//show testimonial
	function showTestimonial($id){
		if( empty($id) ) return false;
		$columns = 'A.*, ';
		$columns .= 'B.firstname,B.lastname ';
		
		$this->db->select($columns);
		$this->db->from('mlme_testimonials AS A');
		$this->db->join('mlme_users AS B','A.userid=B.userid','left');
		$this->db->where('A.testimonialid',$id);
		$this->db->group_by('testimonialid');
		$query = $this->db->get();
		return ($query->num_rows > 0) ? $query->result() : '';
	}
}